package com.bw.controller;

import com.alibaba.fastjson2.JSONArray;
import com.alibaba.fastjson2.JSONObject;
import com.bw.service.EduService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;

@RestController
public class EduController {
    @Autowired
    EduService service;
    @RequestMapping("/findLl")
    public Object findLl(String nowDate){
        List<Map> list = service.findLl(nowDate);
        JSONObject jsonObject = new JSONObject();
        jsonObject.put("status",0);
        jsonObject.put("msg","");
        JSONObject dataObject = new JSONObject();
        JSONArray xArray = new JSONArray();
        JSONArray yArray = new JSONArray();
        for (Map map : list) {
            xArray.add(map.get("sj"));
        }
        dataObject.put("categories",xArray);

        JSONObject serObject = new JSONObject();
        serObject.put("name","访客数量");
        JSONArray dataArray = new JSONArray();
        for (Map map : list) {
            dataArray.add(map.get("fks"));
        }
        serObject.put("data",dataArray);
        yArray.add(serObject);
        dataObject.put("series",yArray);

        jsonObject.put("data",dataObject);
        return jsonObject;
    }
    @RequestMapping("/findJy")
    public Object findJy(String nowDate){
        List<Map> list = service.findJy(nowDate);
        JSONObject jsonObject = new JSONObject();
        jsonObject.put("status",0);
        jsonObject.put("msg","");
        JSONObject dataObject = new JSONObject();
        JSONArray colArray = new JSONArray();
        JSONArray rowArray = new JSONArray();

        JSONObject jsonObject1 = new JSONObject();
        jsonObject1.put("name","名称");
        jsonObject1.put("id","subsys");
        colArray.add(jsonObject1);

        JSONObject jsonObject2 = new JSONObject();
        jsonObject2.put("name","订单总额");
        jsonObject2.put("id","module");
        colArray.add(jsonObject2);

        JSONObject jsonObject3 = new JSONObject();
        jsonObject3.put("name","下单人数");
        jsonObject3.put("id","business");
        colArray.add(jsonObject3);

        JSONObject jsonObject4 = new JSONObject();
        jsonObject4.put("name","订单数");
        jsonObject4.put("id","name");
        colArray.add(jsonObject4);
        dataObject.put("columns",colArray);

        for (Map map : list) {
            JSONObject rowObject = new JSONObject();
            rowObject.put("subsys",map.get("name"));
            rowObject.put("module",map.get("je"));
            rowObject.put("business",map.get("rs"));
            rowObject.put("name",map.get("sl"));
            rowArray.add(rowObject);
        }

        dataObject.put("rows",rowArray);
        jsonObject.put("data",dataObject);
        return jsonObject;
    }

    @RequestMapping("/findSl")
    public Object findSl(String nowDate,String sz){
        List<Map> list = service.findSl(nowDate, sz);
        JSONObject jsonObject = new JSONObject();
        jsonObject.put("status",0);
        jsonObject.put("msg","");
        jsonObject.put("data",list.get(0).get("sl"));
        return jsonObject;
    }

    @RequestMapping("/findDd")
    public Object findDd(String nowDate){
        List<Map> list = service.findDd(nowDate);
        JSONObject jsonObject = new JSONObject();
        jsonObject.put("status",0);
        jsonObject.put("msg","");
        JSONObject dataObject = new JSONObject();
        JSONArray colArray = new JSONArray();
        JSONArray rowArray = new JSONArray();

        JSONObject jsonObject1 = new JSONObject();
        jsonObject1.put("name","学科、类别、课程名称");
        jsonObject1.put("id","subsys");
        colArray.add(jsonObject1);

        JSONObject jsonObject2 = new JSONObject();
        jsonObject2.put("name","下单金额");
        jsonObject2.put("id","module");
        colArray.add(jsonObject2);
        dataObject.put("columns",colArray);

        for (Map map : list) {
            JSONObject rowObject = new JSONObject();
            rowObject.put("subsys",map.get("name"));
            rowObject.put("module",map.get("je"));
            rowArray.add(rowObject);
        }
        dataObject.put("rows",rowArray);
        jsonObject.put("data",dataObject);
        return jsonObject;
    }


}
